package com.newbingo.action;

import java.util.Date;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.newbingo.dto.MemberDto;
import com.newbingo.entity.BettingItem;
import com.newbingo.service.imple.IBettingItemService;
import com.newbingo.util.Pager;

/**
 * 投注项Action
 * @author ChansonYan
 */
public class BettingItemAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//Spring注入属性
	private IBettingItemService bettingItemService;
	//投注项申明，供增删改操作
	private BettingItem bettingItem;
	//批量添加投注项
	private Integer[] amount=new Integer[20];
	private Integer[] cellId=new Integer[20];
	private Integer periodGameId;
	//分页查询条件
	private int start;
	private int limit;
	private Integer pgno;
	private Date startTime;
	private Date endTime;
	private Pager pager;
	//判断方法是否正确执行
	private Boolean success = false;


	/*
	 * 会员在投注格中填入筹码，进行提交，批量保存数据
	 */
	public String saveBettingItem() {
		HttpSession session=ServletActionContext.getRequest().getSession();
		if(session.getAttribute("member")!=null){
			MemberDto memberDto=(MemberDto)session.getAttribute("member");
			bettingItemService.createBettingItem(amount, cellId, memberDto.getUno(),periodGameId);
			success=true;
		}else{
			success=false;
		}
		
		return SUCCESS;
	}

	/*
	 * 修改投注格信息
	 */
	public String updateBettingItem() {
		if (bettingItem == null) {
			success = false;
		} else {
			bettingItemService.updateBettingItem(bettingItem);
			success = true;
		}

		return SUCCESS;
	}

	/*
	 * 分页查询
	 * 
	 * @return
	 */
	public String findByPage() {
		setPager(bettingItemService.findByPage(start, limit, pgno, startTime,
				endTime));
		success = true;
		return SUCCESS;
	}

	@JSON(serialize=false)
	public IBettingItemService getBettingItemService() {
		return bettingItemService;
	}

	public void setBettingItemService(IBettingItemService bettingItemService) {
		this.bettingItemService = bettingItemService;
	}

	public BettingItem getBettingItem() {
		return bettingItem;
	}

	public void setBettingItem(BettingItem bettingItem) {
		this.bettingItem = bettingItem;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public Integer getPgno() {
		return pgno;
	}

	public void setPgno(Integer pgno) {
		this.pgno = pgno;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public Integer[] getAmount() {
		return amount;
	}

	public void setAmount(Integer[] amount) {
		this.amount = amount;
	}

	public Integer[] getCellId() {
		return cellId;
	}

	public void setCellId(Integer[] cellId) {
		this.cellId = cellId;
	}

	public Integer getPeriodGameId() {
		return periodGameId;
	}

	public void setPeriodGameId(Integer periodGameId) {
		this.periodGameId = periodGameId;
	}
	
	
}
